home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / netid.zip / NETIDTSR.ASM < prev    next >
Assembly Source File  |  1992-09-03  |  15KB  |  409 lines

  1.  
  2. ; Public Domain - credits to Matthew Staben, Staben Technologies
  3. ;                                            811 West 14th Avenue
  4. ;                                            Spokane, WA  99204
  5. ;
  6.  
  7. .Model small
  8. .Code
  9. ;============================================:
  10. ; Variables which are internally used by the :
  11. ; program.                                   :
  12. ;============================================:
  13. safearea        DB      512 dup ( ? )          ; temp storage buffer
  14. EMPTYSPOT       DB      'D'
  15. ENVSTR          DB      'USER='                 ; Env. variable to find
  16. ENVLEN          EQU     5                       ; length of env variable
  17. envseg          DW      0                        ; environment seg
  18. envoff          DW      0                        ; environment offset
  19. objectseg       DW      0                       ; object segment
  20. objectoff       DW      0                       ; object offset
  21. startpos        DW      0                       ; network buffer too short
  22. onezero         DB      0                       ; was it appended?
  23.  
  24.  
  25. RequestBuffer           Label   Byte
  26. PacketLengthLow         db      2               ; request buffer 2 bytes long
  27. PacketLengthHigh        db      0
  28. Function                db      22              ; sub function to get user info
  29. ConnectionNumber        db      ?               ; logical connection number
  30.  
  31. ReplyBuffer             Label   Byte
  32. ReturnLengthLow         db      62              ; Reply is 62 bytes long
  33. ReturnLengthHigh        db      0
  34. UniqueID                dd      ?               ; Station's ID #
  35. Typex                   dw      ?
  36. ObjectName              db      48 dup ( ? )    ; USERNAME 1-47 characters
  37. LogTime                 db      8  dup ( ? )    ; Time user logged in
  38.  
  39. old_1ch_vector  dd      0
  40. timer        DW    0
  41.  
  42. new_1ch_vector  proc    far
  43.         
  44.  
  45.                 sti                             ; renable 8088 irq, the
  46.                                                 ; 8088 (80x86) will disable
  47.                                                 ; when called.  The 8259
  48.                                                 ; will not allow anything
  49.                                                 ; to interrupt until
  50.                                                 ; this routine is done
  51.                 push ax
  52.                 push bx
  53.                 push cx
  54.                 push dx
  55.                 push si
  56.                 push di
  57.                 push bp
  58.                 push ds
  59.                 push es
  60.  
  61.                 ;note call to old vecter is an intersegment far call
  62.         
  63.                 pushf                           ; push flags to simulate int
  64.                 call cs:old_1ch_vector          ; chain old routine
  65.         
  66.                 mov al,20h                      ; send eoi to 8259
  67.                 mov dx,20h
  68.                 out dx,al
  69.                 
  70.                 ;===============================:
  71.                 ; first, test for MS-DOS or 4DOS:
  72.                 ;===============================:
  73.                 mov     ax, 0D44Dh              ; 4DOS swap area
  74.                 mov     bx, 0
  75.                 int     2Fh                     ; and interrupt it
  76.                 ;===============================:
  77.                 ;IF ax = 44DD, 4DOS is used.    :
  78.                 ;===============================:
  79.                 cmp     ax, 44DDh               ; compare the deal
  80.                 je      IS_4DOS                 ; and if equal, its 4DOS
  81.                 mov     ax, 352Eh               ; find the master env
  82.                 int     21h
  83.                 mov     es, [es:2Ch]            ; es = environment segment
  84.                 jmp     short   dos_checked     ; jump past 4dos stuff
  85.         is_4dos:
  86.                 mov     es, cx                  ; es = 4dos environment segment
  87.                 mov     es, [es:2Ch]
  88.         dos_checked:            
  89.                 mov     [cs:envseg], es
  90.                 xor     di, di                  ; point to start of env in es:di
  91.                 cld                             ; scan in forward
  92. FIND_STRING:                                    ; - loop thru 1 by 1
  93.                 test    [byte ptr es:[di]], -1  ; end of env?
  94.                 jnz     check_string            ; nope... continue
  95.                 jmp     short   no_environment  ; error...
  96. CHECK_STRING:           
  97.                 push    cs
  98.                 pop     ds
  99.                 mov     si, offset ENVSTR       ; point to USERNAME
  100.                 mov     bx, di                  ; save ptr to start
  101.                 mov     cx, envlen              ; length of envstr
  102.                 repe    cmpsb                   ; compare
  103.                 je      ALL_PASSED              ; found it!
  104.                 mov     di, bx                  ; restore ptr to start
  105.                 xor     al, al                  ; scan for end of string
  106.                 mov     cx, -1                  ; FFFF <- cx
  107.                 repne   scasb
  108.                 jmp     short   find_string     ; go back for next string
  109.                 
  110. ALL_PASSED:
  111.                 mov     [cs:envoff], di
  112.                 clc
  113.                 mov     [cs:onezero], 0
  114.                 jmp     BEGIN
  115.                 
  116. NO_ENVIRONMENT:
  117.                 ;===========================:
  118.                 ; This procedure is called  :
  119.                 ; if the environment string :
  120.                 ; does not exist.           :
  121.                 ;===========================:
  122.                 ; so, create it!            :
  123.                 ;===========================:
  124.                 
  125.                 mov     [cs:onezero],2
  126.                 mov     ax, [cs:envseg]
  127.                 mov     es, ax
  128.                 xor     di, di
  129.                 
  130.                 ; look for pair of zeros, the second zero is the new begin
  131. lookfor:                
  132.                 mov     ah, [byte ptr es:[di]]
  133.                 cmp     ah, 0
  134.                 je      first_zero
  135.                 inc     di
  136.                 jmp     lookfor
  137. first_zero:
  138.                 inc     di
  139.                 mov     ah, [byte ptr es:[di]]
  140.                 cmp     ah, 0
  141.                 jne     lookfor
  142.                 
  143. is_zero:
  144.                 mov     [byte ptr es:[di]], 85
  145.                 inc     di
  146.                 mov     [byte ptr es:[di]], 83
  147.                 inc     di
  148.                 mov     [byte ptr es:[di]], 69
  149.                 inc     di
  150.                 mov     [byte ptr es:[di]], 82
  151.                 inc     di
  152.                 mov     [byte ptr es:[di]], 61    
  153.                 inc     di
  154.                 mov     [cs:envoff], di
  155.                 jmp     begin
  156.  
  157. EXIT_OUT:
  158.                 jmp     bye_bye
  159. BEGIN:
  160.  
  161. MODIFY_ENV:
  162.                 ;==================================================:
  163.                 ; Let's get the username and slip into the env     :
  164.                 ;==================================================:
  165.                 
  166.                 mov     AH,0DCh                 ; function to get connection #
  167.                 int     21h
  168.                 mov     CS:ConnectionNumber,AL
  169.  
  170.                 mov     AH,0E3h                 ; log request function #
  171.  
  172.                 mov     DX,seg cs:RequestBuffer
  173.                 mov     DS,DX
  174.                 mov     DX,seg cs:ReplyBuffer
  175.                 mov     ES,DX
  176.                 lea     SI,cs:RequestBuffer        ;  DS:SI points to Request Buffer
  177.                 lea     DI,cs:ReplyBuffer          ;  ES:DI points to Reply Buffer
  178.                                               
  179.                 int     21h
  180.  
  181. ;  Return the name
  182.  
  183.        WRITE_OUT:
  184.                 ; here, we actually write out the environment.       
  185.                 mov     ax, seg cs:objectname
  186.                 mov     es, ax
  187.                 mov     di, offset cs:objectname
  188.                 mov     [cs:objectoff], di
  189.                 mov     [cs:objectseg], es
  190.                 mov     ax, cs
  191.                 mov     ds, ax
  192.                 mov     si, offset safearea
  193.                 xor     dx, dx
  194.                 xor     bx, bx
  195.                 xor     cx, cx
  196.                 
  197.                 cmp     [cs:onezero], 2
  198.                 jne     REPLACEUPTO
  199.                 
  200.                 ; 
  201.                 ; just fill it out and add two zeros
  202.                 ;
  203.           APPEND:
  204.                 mov     es, [cs:objectseg]
  205.                 mov     di, [cs:objectoff]
  206.                 mov     ah, [byte ptr es:[di]]
  207.                 cmp     ah, 0
  208.                 je      addtwo
  209.                 inc     [cs:objectoff]
  210.                 mov     es, [cs:envseg]
  211.                 mov     di, [cs:envoff]
  212.                 inc     [cs:envoff]
  213.                 mov     [byte ptr es:[di]], ah
  214.                 jmp     append
  215.       addtwo:
  216.                 mov     es, [cs:envseg]
  217.                 mov     di, [cs:envoff]
  218.                 jmp     addtwozeros
  219.  
  220.       samelength:
  221.                 cmp     ah, 0
  222.                 jne     retsame
  223.                 jmp     did_it
  224.                                 
  225.       REPLACEUPTO:
  226.                 ; 
  227.                 ; replace the environment up to the first zero
  228.                 ;
  229.                 mov     es, [cs:objectseg]
  230.                 mov     di, [cs:objectoff]
  231.                 mov     ah, [byte ptr es:[di]]  ; next net buffer char
  232.                 mov     es, [cs:envseg]
  233.                 mov     di, [cs:envoff]
  234.                 mov     al, [byte ptr es:[di]]
  235.                 ; check if both are zero
  236.                 cmp     al, ah
  237.                 je      samelength
  238.            retsame:
  239.                 ; check if zero has been reached in environment
  240.                 cmp     al, 0
  241.                 je      ENDREPLACE
  242.                 ; check if zero has been reached in net-buffer
  243.                 cmp     ah, 0
  244.                 je      ENDNETBUF
  245.                 mov     es, [cs:envseg]
  246.                 mov     di, [cs:envoff]
  247.                 mov     [byte ptr es:[di]], ah
  248.                 inc     [cs:envoff]
  249.                 inc     [cs:objectoff]
  250.                 jmp     REPLACEUPTO
  251.  
  252.       ENDNETBUF:
  253.                 ; 
  254.                 ; scan thru environment to next char, saving the current
  255.                 ; position in the environment for replacing
  256.                 ;
  257.                 mov     di, [cs:envoff]
  258.                 mov     [cs:startpos], di
  259.                 ; find a zero
  260.          envscan:
  261.                 inc     di
  262.                 mov     ah, [byte ptr es:[di]]
  263.                 cmp     ah, 0
  264.                 je      endenvscan
  265.                 jmp     envscan
  266.          endenvscan:
  267.                 mov     [cs:envoff], di
  268.                 
  269.       ENDREPLACE:
  270.                 ; 
  271.                 ; save the rest of the environment in the buffer
  272.                 ;
  273.                 mov     di, [cs:envoff]
  274.                 cmp     [cs:startpos], 0
  275.                 jne     checkstart
  276.                 mov     [cs:startpos], di
  277.          checkstart:
  278.                 mov     es, [cs:envseg]
  279.                 mov     di, [cs:envoff]
  280.                 mov     ah, [byte ptr es:[di]]
  281.                 cmp     ah, 0
  282.                 jne     notzero
  283.                 inc     di
  284.                 mov     ah, [byte ptr es:[di]]
  285.                 dec     di
  286.                 cmp     ah, 0
  287.                 je      checkout
  288.          
  289.          notzero:
  290.                 mov     ah, [byte ptr es:[di]]
  291.                 mov     [byte ptr ds:[si]], ah
  292.                 inc     [cs:envoff]
  293.                 inc     si
  294.                 inc     dl
  295.                 jmp     checkstart
  296.       
  297.          checkout:
  298.        
  299.       FILLENVIRONMENT:
  300.                 ; 
  301.                 ; if the buffer was too long, we still have some chars to
  302.                 ; slip into the environment from the network buffer
  303.                 ;
  304.                 mov     es, [cs:objectseg]
  305.                 mov     di, [cs:objectoff]
  306.                 mov     ah, [byte ptr es:[di]]
  307.                 cmp     ah, 0
  308.                 je     fillitup
  309.            fillnet:
  310.                 mov     es, [cs:objectseg]
  311.                 mov     di, [cs:objectoff]
  312.                 mov     ah, [byte ptr es:[di]]
  313.                 cmp     ah, 0
  314.                 je      fillitup
  315.                 inc     [cs:objectoff]
  316.                 mov     es, [cs:envseg]
  317.                 mov     di, [cs:startpos]
  318.                 mov     [byte ptr es:[di]], ah
  319.                 inc     [cs:startpos]
  320.                 jmp     fillnet
  321.                 
  322.            fillitup:
  323.                 mov     di, [cs:startpos]
  324.                 mov     [cs:envoff], di
  325.                 mov     ax, cs
  326.                 mov     ds, ax
  327.                 mov     si, offset safearea
  328.                 inc     dl
  329.            filloop:
  330.                 mov     di, [cs:envoff]
  331.                 mov     es, [cs:envseg]
  332.                 mov     ah, [byte ptr ds:[si]]
  333.                 inc     si
  334.                 mov     [byte ptr es:[di]], ah
  335.                 inc     [cs:envoff]
  336.                 inc     cx
  337.                 cmp     cx, dx
  338.                 je      addtwozeros
  339.                 jmp     filloop
  340.          
  341.            addtwozeros:
  342.                 mov     [byte ptr es:[di]], 0
  343.                 inc     di
  344.                 mov     [byte ptr es:[di]], 0
  345.  
  346. did_it:
  347. bye_bye:
  348.                 
  349.  
  350.                 pop es
  351.                 pop ds
  352.                 pop bp
  353.                 pop di
  354.                 pop si
  355.                 pop dx
  356.                 pop cx
  357.                 pop bx
  358.                 pop ax
  359.                 iret
  360.                 endp
  361.  
  362.  
  363.  
  364. ;----------------------------------------------------------------------------
  365. _1ch_install    proc
  366.  
  367.                 cli                             ; disable interrupts
  368.                                                 ; while diddling vectors
  369.  
  370.                 ; get old vector and save it
  371.                 mov ah, 35h                     ; get vector
  372.                 mov al, 1ch                     ; of int 1ch
  373.                 int 21h
  374.                 mov  word ptr old_1ch_vector, bx
  375.                 mov  word ptr old_1ch_vector + 2, es
  376.  
  377.                 push ds                         ; save ds, int 25h uses it
  378.  
  379.                 ; get address of new vector and install it
  380.                 mov dx, cs
  381.                 mov ds, dx
  382.                 mov dx,  offset new_1ch_vector
  383.                 mov ah, 25h                     ; set vector
  384.                 mov al, 1ch                     ; of 1ch
  385.                 int 21h
  386.  
  387.                 pop ds
  388.                 sti                             ; reenable interrupts
  389.                 ret
  390.                 endp
  391.  
  392. ;----------------------------------------------------------------------------
  393. main            proc
  394.                 call _1ch_install
  395.                 mov    [timer], 0h
  396.                 
  397.                 ; terminate and stay resident
  398.                 mov dx, ((offset pgm_length + 15) / 16) + 640
  399.                 mov ah, 31h
  400.                 mov al, 00h
  401.                 int 21h
  402.                 endp
  403.  
  404. pgm_length      equ $ - main                    ; remove un-needed code
  405.  
  406.                 end  main                       ; specify start location
  407.  
  408.  
  409.